// # Place all the behaviors and hooks related to the matching controller here.
// # All this logic will automatically be available in application.js.
// # You can use CoffeeScript in this file: http://coffeescript.org/


// # jQuery ->
// #   subcategories = $('#micropost_subcategory_id').html()
// #   console.log(subcategories)
// #   $('#micropost_category_id').change ->
// #     category = $('#micropost_category_id :selected').text()
// #     options = $(subcategories).filter("optgroup[label='#{category}']").html() 

// #     if options
// #         $('#micropost_subcategory_id').html(options)
// #     else
// #         $('#micropost_subcategory_id').empty()

// http://stackmirror.caup.cn/page/s1b3jowl1ruh
  jQuery(document).on('turbolinks:load', function() {
    var subcategories;
    subcategories = $('#micropost_subcategory_id').html();
    console.log(subcategories);
    return $('#micropost_category_id').change(function() {
      var category, options;
      category = $('#micropost_category_id :selected').text();
      options = $(subcategories).filter("optgroup[label='" + category + "']").html();
      if (options) {
        return $('#micropost_subcategory_id').html(options);
      } else {
        return $('#micropost_subcategory_id').empty();
      }
    });
  })
